-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Criteria #43
Criteria #43
Conversation
- Style options also mark the style's spec - hidden section is currently broken
This means that if the global criteria disables a feature, later critiera cannot reenable it. I'll deal with this later.
This definitely can't stay around either, but good enough for now.
Also add appropriate error messages
I want to refactor this eventually, but I don't know exactly how yet.
criteria.c
Outdated
*value = '\0'; | ||
++value; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: else on same line as }.
This also happens in many other places.
config.c
Outdated
void finish_style(struct mako_style *style) { | ||
free(style->font); | ||
free(style->format); | ||
} | ||
|
||
// Update `target` with the values specified in `style`. If a failure occurs, | ||
// `target` will remain unchanged. | ||
bool apply_style(struct mako_style *style, struct mako_style *target) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally in C we prefer to have the struct on which the function operates always as the first argument. It seems the comment "target
will remain unchanged" is outdated.
Also to make it more obvious that an argument isn't mutated, you can make it const
.
return true; | ||
} | ||
|
||
bool parse_boolean(const char *string, bool *out) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be reused in config.c
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning on moving this and the existing stuff into a parse.c
utility-type file in another PR, which would include making config.c
use it. config.c
is getting a little bit out of control.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, nice idea. So let's keep it that way for now.
case '"': | ||
state = MAKO_PARSE_STATE_NORMAL; | ||
break; | ||
case ' ': |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
// string, so that's a safe length to use for the buffer. | ||
int token_max_length = strlen(string) + 1; | ||
char token[token_max_length]; | ||
memset(token, 0, token_max_length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling memset
, you can initialize token
with {0}
and all fields will be set to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use initialization syntax with a variable-length array. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know that. RIP
criteria.c
Outdated
int token_max_length = strlen(string) + 1; | ||
char token[token_max_length]; | ||
memset(token, 0, token_max_length); | ||
int token_location = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a size_t
criteria.c
Outdated
// Iterate through `criteria_list`, applying the style from each matching | ||
// criteria to `notif`. Returns the number of criteria that matched, or -1 if | ||
// a failure occurs. | ||
int apply_each_criteria(struct wl_list *criteria_list, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can return a ssize_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work. I wish I could read PRs like this everyday :)
Apart from these - mostly style and nitpick - issues, I'll test this patch out and it'll probably be ready to merge!
Noting this here mostly to hold myself to it: I'm working on updating the manpage to go with this. I can either tack that on to this PR or post another one soon. |
Oh, right, I think this should be done in this PR, so that the manpage is not out-of-date. |
We could strip HTML tags for instance. But yeah, it's not ideal.
Agreed, this can be filled as a follow-up issue for later. |
- _urgency_ (one of "low", "normal", "high") | ||
- _category_ (string) | ||
- _desktop-entry_ (string) | ||
- _actionable_ (boolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing "hidden"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it, LGTM! :D
Thanks, nice work! |
At long last, criteria are here! The syntax is as discussed on #3, and is fairly flexible:
Note that booleans can be specified either as normal, or as bare words (with leading
!
to negate). Quoting, escaping, and escaping within quotes works, the literal name of the app in the above example isTest App\"
. The backslash within the quotes is unnecessary but doesn't hurt anything. Leaving quotes unmatched or backslashes trailing will raise errors. (I bashed on it a lot, but more testing of the parsing is much appreciated!)Style options within the global section are stored in an empty criteria (which therefore matches everything). It is always the first in the list, and always initialized with the default style options before parsing the configuration.
Things that can currently be overridden:
colors
margin.{top,bottom}
(I have no idea why you would want this.)padding
border_size
font
format
default_timeout
ignore_timeout
markup
Things that don't work yet:
width
(Currently forced to the surface width byrender
.)height
(I think this is just being completely ignored at the moment?)margin.{left,right}
(Need to rework how the surface size is calculated.)actions
(You can set it and it's stored, but turning them off doesn't disable them. See also other caveats below.)Other caveats:
markup
andactions
are going to end up being useful. Their enabled status gets sent as part of the XDG bus setup, which means they can only really be either on or off globally.markup
"works" and you see the raw HTML, but since I don't think anyone would ever want this, it might be better to just make it global again. (That way if it's disabled, apps just send plaintext instead.)actions
seems slightly more useful. We would want to advertise it as enabled globally if any criteria has it enabled, and then just ignore interactions with notifications where it has been disabled.[hidden]
section is now fully style-able. However, I'm not happy with the current implementation. I'm going to continue working on a way to make it less of a special case.Closes #3.